package com.xin.chaingeneration.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xin.chaingeneration.common.ResponseEntity;
import com.xin.chaingeneration.entity.Cooperation;
import com.xin.chaingeneration.service.CooperationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/cooperation")
public class CooperationController {

    @Autowired
    CooperationService cooperationService;

    @PostMapping("/saveCooperations")
    public ResponseEntity<String> saveNews(@RequestBody List<Cooperation> cooperationList){



        cooperationService.saveBatch(cooperationList);

        return ResponseEntity.success("保存成功");
    }

    @GetMapping("/getByProductId/{productId}")
    public ResponseEntity<List<Cooperation>> getByProductId(@PathVariable Long productId){
        LambdaQueryWrapper<Cooperation> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Cooperation::getProductId,productId);

        List<Cooperation> list = cooperationService.list(queryWrapper);

        ResponseEntity<List<Cooperation>> responseEntity = ResponseEntity.success(list);
        responseEntity.setCode(1);

        return responseEntity;
    }
}
